import { createTempOrderNo, currentUserID } from "@/utils/common.js";
import { utils } from 'hi-ui';
//商品拆分数据集配置
export default {
    id: "SplitEntity",
    returnTotal:true,
    modelFile: "store/split/dataset/SplitEntity.xml",
    sortFields: [
        "FID",
        "FNUMBER",
        "FGOODSNUMBER",
        "FBARCODE",
        "FDESC",
        "FBRAND",
        "FUNIT",
        "FAMOUNT",
        "FSTORAGE",
        "FPRICE",
        "FMONEY",
        "FNOTE",
        "FUSERID",
        "FCREATEDATE",
        "FAUDIT",
        "FENTERPRISEDESC",
        "FENTERPRISEID",
        "FSHOPDESC",
        "FSHOPDESCID",
        "FKCAMOUNT",
        "FSUPERVISIONCODE"
    ],
    fields: {
        FID: {
            name: "FID", //字段ID
            label: "ID", //字段描述
            dbtype: "dbString", //数据类型
            default: {
                //默认值
                //rule: 'first', //prior   填充规则
                exps: (data) => {
                    //填充表达式
                    return utils.string.guid();
                },
            },
        },
        FNUMBER: {
            name: "FNUMBER", //字段ID
            label: "单号", //字段描述
            dbtype: "dbString", //数据类型
            required: true,
            readonly: true,
            length: 25,
            default: {
                //默认值
                //rule: 'first', //prior   填充规则
                exps: (data) => {
                    //填充表达式
                    return createTempOrderNo();
                },
            },
        },
        FUSERID: {
            name: "FUSERID", //字段ID
            label: "创建人", //字段描述
            dbtype: "dbString", //数据类型
            required: true,
            readonly: true,
            length: 25,
            default: {
                //默认值
                exps: (data) => {
                    //填充表达式
                    return currentUserID();
                },
            },
        },
        FCREATEDATE: {
            name: "FCREATEDATE", //字段ID
            label: "创建日期", //字段描述
            dbtype: "dbDate", //数据类型
            required: true,
            readonly: true,
            default: {
                //默认值
                exps: (data) => {
                    //填充表达式
                    return utils.date.format(new Date(), "yyyy-MM-dd HH:mm:ss");
                },
            },
        },
        FGOODSNUMBER: {
            name: "FGOODSNUMBER", //字段ID
            label: "店内编码", //字段描述
            dbtype: "dbString", //数据类型
            required: true,
            length: 25,
        },
        FSUPERVISIONCODE: {
            name: "FSUPERVISIONCODE", //字段ID
            label: "电子监管码", //字段描述
            dbtype: "dbString", //数据类型
            length: 25,
        },
        FENTERPRISEDESC: {
            name: "FENTERPRISEDESC", //字段ID
            label: "企业名称", //字段描述
            dbtype: "dbString", //数据类型
            length: 25,
        },
        FENTERPRISEID: {
            name: "FENTERPRISEID", //字段ID
            label: "企业ID", //字段描述
            dbtype: "dbString", //数据类型
            length: 25,
        },
        FBARCODE: {
            name: "FBARCODE", //字段ID
            label: "条形码", //字段描述
            dbtype: "dbString", //数据类型
            required: true,
            length: 25,
        },
        FDESC: {
            name: "FDESC	", //字段ID
            label: "通用名称 ", //字段描述
            dbtype: "dbString", //数据类型
            required: true,
            length: 25,
        },
        FSPEC: {
            name: "FSPEC", //字段ID
            label: "规格", //字段描述
            dbtype: "dbString", //数据类型
            required: true,
            readonly: true,
            length: 100,
        },
        FBRAND: {
            name: "FBRAND", //字段ID
            label: "品牌", //字段描述
            dbtype: "dbString", //数据类型
            readonly: true,
            //required: true, 

        },
        FUNIT: {
            name: "FUNIT	", //字段ID
            label: "单位 ", //字段描述
            dbtype: "dbString", //数据类型
            required: true,
            readonly: true,
            length: 25,
        },

        FAMOUNT: {
            name: "FAMOUNT", //字段ID
            label: "数量", //字段描述
            dbtype: "dbFloat", //数据类型
            required: true,
            length: 25,
        },
        FKCAMOUNT: {
            name: "FKCAMOUNT", //字段ID
            label: "可用库存", //字段描述
            dbtype: "dbFloat", //数据类型
            readonly: true,
        },
        FPRICE: {
            name: "FPRICE", //字段ID
            label: "单价", //字段描述
            dbtype: "dbFloat", //数据类型
            required: true,
            readonly: true,
        },

        FMONEY: {
            name: "FMONEY", //字段ID
            label: "总金额", //字段描述
            dbtype: "dbFloat", //数据类型
            required: true,
            readonly: true,
        },
        FSTORAGE: {
            name: "FSTORAGE", //字段ID
            label: "仓库", //字段描述
            dbtype: "dbString", //数据类型
        },
        FNOTE: {
            name: "FNOTE", //字段ID
            label: "备注", //字段描述
            dbtype: "dbString", //数据类型
            length: 250,
        },
        FAUDIT: {
            name: "FAUDIT", //字段ID
            label: "审核", //字段描述
            dbtype: "dbInt", //数据类型
        },
        FSHOPDESC: {
            name: "FSHOPDESC", //字段ID
            label: "店铺", //字段描述
            dbtype: "dbString", //数据类型
            required: true,
            readonly: true,
            length: 25,
        },
        FSHOPDESCID: {
            name: "FSHOPDESCID", //字段ID
            label: "店铺编号", //字段描述
            dbtype: "dbString", //数据类型
            required: true,
            length: 25,
        },

    },
    validateList: [{
        "expr": function(store) {
            var data = store.data;
            for (var i = 0; i < data.length; i++) {
                var item = data[i];
                if (item.FAMOUNT * 1 <= 0) {
                    /*  this.$message.error(`【${item.FAMOUNT}】数量必须大于零`)
                     return */
                    let error = new Error(`【${item.FDESC}】数量必须大于零`)
                    return error
                }
                var FKCAMOUNT = item.FKCAMOUNT,
                    FAMOUNT = item.FAMOUNT || 0;
                if (FAMOUNT > FKCAMOUNT) {
                    let error = new Error(item.FDESC + "数量不能大于可用库存：" + item.FKCAMOUNT);
                    return error
                }


            }

        }
    }]
}